home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-17 | 9.4 KB | 230 lines | [TEXT/ttxt] |
- /*
- * chipmunk-basic-3.2.x.sit.hqx
- * Quick Reference and FAQ
-
- * Chipmunk Basic is (c) Copyright 1990,1994 Ronald H. Nicholson, Jr.
- * ALL RIGHTS RESERVED
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY OF ANY KIND; not even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- ---
- Quick Reference for Chipmunk Basic v3.2 - PPC Macintosh version 95Aug
- ported by Ronald H. Nicholson, Jr. rhn@netcom.com
-
- - The interpreter includes an dumb old fashioned line number based editor.
- (enter a line, delete a line, edit one line at a time).
- - Line numbers are required.
- - The variable types are long floats, short integers and strings with a
- maximum length of 254 characters. Variable names can be up to 31
- characters long and are case insensitive.
- - Math is done using the built-in double precision IEEE math. Trigonometric
- functions are all in radians.
-
- Operators, functions and statements include:
-
- + - * / ^ mod and or xor not > < >= <= <> =
- sqr() log() exp() sin() cos() tan() atn() pi
- abs() sgn() int() rnd() peek() val() asc() len()
- mid$() right$() left$() str$() chr$()
- goto if then else endif gosub return select case
- for to step next while wend
- rem let dim data read restore field$()
- input print open for output append as close# load save
- inkey$ input$ eof() files fgetbyte# fseek#
- run stop end exit quit cont renum new clear def fn
- date$ time$ timer push() pop sound morse say sub
- cls gotoxy moveto lineto graphics window scrn mouse()
- home get htab vtab pos() varptr peek() poke fre
-
- ---
- Some Simple Examples:
-
- for i=1 to 10 : print i : next i
-
- c$ = a$ + b$ : rem string concatenation
- a$ = inkey$ : rem inkey$ is non-blocking
-
- load "sieve.bas" : rem load TEXT file as a Basic program
- : rem file names should have .bas extension
-
- open "filename" for output as #1 : print #1, "hello world" : close #1
-
- gotoxy 5,10 : print "here" : rem text window (0,0 origin)
- x = pos(0) : rem text cursor horizontal location
- y = pos(-1) : rem vertical text cursor location
-
- graphics 0 : moveto 10,10 : lineto 110,80 : rem draw graphics line
-
- ---
- Frequently Asked Questions:
-
- Q: Is more documentation on learning how to program in the BASIC language?
- A: The language is mostly compatible with books on programming in the BASIC
- language that were published between 1978 and 1988. Since these are mostly
- out of print, your best bet is to try your local public library.
-
- Q: Is there any way to redirect print statements to the printer?
- A: No, there is no way to make this work with current MacOS printer drivers.
- I recommend printing to a file, and then using SimpleText to print.
-
- Q: Why can't I load a text file using the "Open" menu?
- A: Chipmunk Basic requires that Basic program file names end with a ".bas"
- suffix. However, if you hold down the option key, it will try to open any
- TEXT file.
-
- Q: How do I make my own sprites?
- A: I use ResEdit (available from ftp.apple.com). Just paste the new sprite
- 'ICN#' and 'cicn's into the resource fork of your Basic program. Resource
- ID's 128-148 are reserved for the Chipmunk Basic interpreter, so please use
- a high resource ID number. A 'cicn' resource must have a corresponding
- 'ICN#' resource in order for Chipmunk Basic to display it.
-
- Q: Why can't I make my graphics window bigger?
- If you have enough memory in your Mac, try increasing the Preferred Memory
- requirements of Chipmunk Basic using the Finder Get Info dialog. Also try
- decreasing the number of colors in the Monitors Control Panel.
-
- Q: Why won't this Microsoft QuickBasic program run? ...
- A: Chipmunk Basic was never intended to be exactly compatible with any other
- commercial BAISC language product. It does include most of the features of
- ANSI BASIC language definition. Many BASIC programs that are saved as an
- ASCII text file and that don't use features of a specific computer system can
- be easily ported to Chipmunk Basic.
-
- Q: Can you send me a list of different peeks and pokes?
- A: Peeks and pokes don't have much use on current Mac Systems. If you want to
- live dangerously, you might want to get a copy of SysEqu.h or LoMem.h from
- an old C or 68K assembly language programming package; but don't expect
- anything you do to be compatible with newer MacOS System software.
-
- Q: Is there a compiler for Chipmunk Basic?
- A: No, however there are several commercial Basic compilers on the market and
- rumors of major new support for the BASIC language on the Mac comming next
- year (1996 maybe, I know Nothing ... ).
-
- Q: What is the history of Chipmunk Basic?
- A: In March 1990, p2c, a pascal to c translator was posted to comp.source.misc
- by David Gillespie. One of the test input files was "basic.p". I used the
- c output file to learn about language interpreters and then ported the
- resulting interpreter to my Mac 512KE and then to a PowerMac 7100.
-
- ---
- Some experimental Chipmunk Basic graphics commands:
- * note: The graphics commands in version 3.x are beta test and may be buggy. *
-
- GRAPHICS 0 // show graphics window
- graphics -1 // hide graphics window
- graphics WINDOW x, y, width, height // graphics window setup
-
- graphics MOVETO x,y // Move pen To x,y
- graphics LINETO x,y // draw Line To x,y
- graphics OVAL x,y // oval x wide by y high
- graphics DRAWTEXT a$ // DrawText
- // use MOVETO to position
-
- graphics RECT x1,y1,x2,y2 // FrameRect
- graphics FILLRECT x1,y1,x2,y2,pat# // PaintRect
- graphics OVAL x1,y1,x2,y2 // FrameOval
- graphics FILLOVAL x1,y1,x2,y2,pat# // PaintOval
- graphics PENSETUP xsize, ysize, [ mode, pat# ]
- graphics COLOR i // set RGBForeColor by index
- graphics COLOR r,g,b // red green blue 0-100
-
- graphics PICT x,y,n // draw 'pict' resource n
- graphics TEXTSETUP f, s, m // set up text font, size, mode
-
- graphics (-38) // get graphics window max width
- graphics (-39) // get graphics window max height
-
- SPRITE n x, y, id // sprite n @ x,y using ICN# or cicn id
- // n from 1 to 15, 1 in frontmost plane
- // ICN# 128 - 141 included with chipbasic
- // a cicn requires ICN# with same id.
- sprite n UP x // sprite #n move up x pixels
- sprite n DOWN x // also returns new sprite y coord
- sprite n LEFT x // move LEFT (not turn as in Logo!)
- sprite n RIGHT x
- sprite n TURN d // turn CCW d degrees
- sprite n FORWARD x // move forward x pixels
- sprite n PENUP
- sprite n PENDOWN
- sprite n COLLISION // returns 1st sprite# in contact
-
- ---
- Other unusual and/or experimental features:
-
- morse "CQ DE N6YWU",16,40,13,700 // play morse code
- // MORSE string, dot_wpm, volume, letter_wpm, freq
-
- open "SFGetFile" for input as #2 // "SFPutFile" works for output
- open "COM1:" for input as #3 // *requires* CTB Serial Tool
- open f$ for data input as #4 // data file, no cr<->lf translation
- open f$ for data input // opens resource file
- say "hello world" // *requires* the Speech Manager & Lib
- say "faster", 196, 44, 1 // string, rate, pitch, voice #
- a$ = field$("aa bb cc dd", 2, " ") // "bb", similar to awk fields
- sound 440,0.5,30 // freq, seconds_duration, vol 0-100
- sound 0,8192 // play snd resource 8192
- sound -1,a(0),11100 // play 1 sec. of samples from array a
- sound n,freq(0),dur,vol(0) // play n voices from arrays freq & vol
- graphics WINDOW -1,-1, x,y, 2 // scroll graphics background to (x,y)
- graphics BUTTON title$,x,y,w,h,key_code // draw a standard button
- // the button will input chr$(key_code) when pushed
- graphics BUTTON "",x,y,id,key_code,-4 // using cicn or ICN# id
- graphics EDIT a$ [,w,h] // edit a$ in a text edit box
- call n // calls 68k assembly at address n
- call "beep", i // calls BCMD resource "beep" with 1 param (long *)i
- call "doscript", appname$, doscript$ // send a DoScript AE
- call "applescript", script$ // compiles and executes a script.
- // script$ can also be a string array.
-
- A couple oddball commands included in version 3.2.0 just for testing:
-
- call "fft_polar", real(0), amp(0), phase(0) , size // size must = 2^n
- call "fft_inv", amp(0), phase(0), real(0) , size // inverse fft
-
- call "math$", "mul$", r$, "1234567890", "9876543210"
- // 250 digit string math (add$, sub$, mul$, div$, mod$)
-
-
- - "Preferred Size" from Finder Get Info may limit maximum graphics window size
- - ICN#, cicn, PICT & BCMD resources may be stored the resource fork of a file:
- open "foo.rsrc" for data input : rem with no "as" token,
- // makes the file foo.rsrc the current resource file
- - bigfont options are stored in the Prefs file (edit w/ BBEdit or equiv.)
- - AppleScript scriptable. Try this script from a script editor:
- tell application "chipbasic" to DoScript "print 3+4"
- tell application "chipbasic" to DoScript "exec( \" 5 * 7 \" )"
-
- ---
- Bugs or features:
-
- - All input works like the LINE INPUT statement of other Basic versions.
- - Line numbers above 999999999 will not list.
- - Programs without line numbers can be loaded. However line numbers will be
- added. The target of a GOTO can be a label followed by a colon.
-
- ---
- A sample program:
-
- --- cut here ---
- 1 rem "sieve.bas" , a prime number sieve benchmark
- 2 t = timer
- 3 dim f(8194)
- 4 for i = 0 to 8191 : f(i) = 1 : next i
- 5 s = 8191
- 6 for i = 0 to s
- 7 if f(i) = 0 then goto 11
- 8 p = i+i+3
- 9 for k = i+p to s step p : f(k) = 0 : next k
- 10 c = c+1
- 11 next i
- 12 print c;" primes found in ";
- 13 t = timer-t
- 14 print t;" seconds"
- 15 end
- --- cut here ---
- */
-